package com.chen.exceptionhandler;

import com.chen.exception.BaseException;
import com.chen.pojo.common.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @author chen
 * @version 1.0
 * @create_date 2025/8/15
 * 全局异常处理
 */
@Slf4j
@RestControllerAdvice
public class GlobalExceptionHandler {
    @ExceptionHandler
    public Result exceptionHandler(Exception e) {
        e.printStackTrace();
        if (e instanceof BaseException) {
            return Result.error(e.getMessage());
        }
        return Result.error("系统异常，请联系管理员！");
    }
}
